package com.bw.gmallapi.controller;


import com.bw.gmallapi.common.R;
import com.bw.gmallapi.entity.KeyWordBean;
import com.bw.gmallapi.entity.ProvinceBean;
import com.bw.gmallapi.service.KeyWordService;
import com.bw.gmallapi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

// http://127.0.0.1/sugar/api
// http://127.0.0.1/sugar/api/getGmv
@RestController
@RequestMapping("/sugar/api")
public class SugarController {
    @Autowired
    private  ProductService productService;
    @Autowired
    private KeyWordService keyWordService;


    @RequestMapping("/getGmv")
    public R getGmv(@RequestParam(value = "date",defaultValue = "0") Integer date){
        BigDecimal gmv = productService.getGmv(date);
//        return "{" +
//                "  \"status\": 0," +
//                "  \"msg\": \"\"," +
//                "  \"data\": " + gmv.doubleValue() + "" +
//                "}";
        return R.success(gmv.doubleValue());
    }
    /*
        北京 10000
        上海 200
        南京 300
     */
    @RequestMapping("/getProvinceGmv")
    public R getProvinceGmv(@RequestParam(value = "date",defaultValue = "0") Integer date,
                                 @RequestParam(value = "limit",defaultValue = "10") Integer limit){
        List<ProvinceBean> proGmv = productService.getProGmv(date);
        return R.success(proGmv);
    }

    @RequestMapping("/getKeyWord")
    public R getKeyWord(@RequestParam(value = "date",defaultValue = "0") Integer date){
        List<KeyWordBean> keyWord = keyWordService.getKeyWord(date);
        return R.success(keyWord);
    }
}
